package com.ruoyi.puyu.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.puyu.domain.PuyuLessonStudent;
import com.ruoyi.puyu.service.IPuyuLessonStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学员课时点名Controller
 * 
 * @author wusongwen
 * @date 2024-05-01
 */
@RestController
@RequestMapping("/puyu/lessonstudent")
public class PuyuLessonStudentController extends BaseController
{
    @Autowired
    private IPuyuLessonStudentService puyuLessonStudentService;

    /**
     * 查询学员课时点名列表
     */
    @PreAuthorize("@ss.hasPermi('puyu:lessonstudent:list')")
    @GetMapping("/list")
    public TableDataInfo list(PuyuLessonStudent puyuLessonStudent)
    {
        puyuLessonStudent.setDelFlag(0);
        startPage();
        List<PuyuLessonStudent> list = puyuLessonStudentService.selectPuyuLessonStudentList(puyuLessonStudent);
        return getDataTable(list);
    }

    /**
     * 获取学员课时点名详细信息
     */
    @PreAuthorize("@ss.hasPermi('puyu:lessonstudent:query')")
    @GetMapping(value = "/listLessonStudentSum")
    public AjaxResult listLessonStudentSum()
    {
        return success(puyuLessonStudentService.listLessonStudentSum());
    }

    /**
     * 导出学员课时点名列表
     */
    @PreAuthorize("@ss.hasPermi('puyu:lessonstudent:export')")
    @Log(title = "学员课时点名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PuyuLessonStudent puyuLessonStudent)
    {
        List<PuyuLessonStudent> list = puyuLessonStudentService.selectPuyuLessonStudentList(puyuLessonStudent);
        ExcelUtil<PuyuLessonStudent> util = new ExcelUtil<PuyuLessonStudent>(PuyuLessonStudent.class);
        util.exportExcel(response, list, "学员课时点名数据");
    }

    /**
     * 获取学员课时点名详细信息
     */
    @PreAuthorize("@ss.hasPermi('puyu:lessonstudent:query')")
    @GetMapping(value = "/{lessonStudentId}")
    public AjaxResult getInfo(@PathVariable("lessonStudentId") Long lessonStudentId)
    {
        return success(puyuLessonStudentService.selectPuyuLessonStudentByLessonStudentId(lessonStudentId));
    }

    /**
     * 新增学员课时点名
     */
    @PreAuthorize("@ss.hasPermi('puyu:lessonstudent:add')")
    @Log(title = "学员课时点名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PuyuLessonStudent puyuLessonStudent)
    {
        return toAjax(puyuLessonStudentService.insertPuyuLessonStudent(puyuLessonStudent));
    }

    /**
     * 修改学员课时点名
     */
    @PreAuthorize("@ss.hasPermi('puyu:lessonstudent:edit')")
    @Log(title = "学员课时点名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PuyuLessonStudent puyuLessonStudent)
    {
        return toAjax(puyuLessonStudentService.updatePuyuLessonStudent(puyuLessonStudent));
    }

    /**
     * 删除学员课时点名
     */
    @PreAuthorize("@ss.hasPermi('puyu:lessonstudent:remove')")
    @Log(title = "学员课时点名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lessonStudentIds}")
    public AjaxResult remove(@PathVariable Long[] lessonStudentIds)
    {
        return toAjax(puyuLessonStudentService.deletePuyuLessonStudentByLessonStudentIds(lessonStudentIds));
    }
}
